Component({
  data: {
    selected: 0,
    color: "#999999",
    selectedColor: "#1890ff",
    list: [
      {
        pagePath: "/pages/schedules/schedules",
        text: "班车查询",
        iconClass: "icon-schedule"
      },
      {
        pagePath: "/pages/my-reservations/my-reservations",
        text: "我的预约",
        iconClass: "icon-reservation"
      },
      {
        pagePath: "/pages/user-center/user-center",
        text: "个人中心",
        iconClass: "icon-user"
      }
    ]
  },
  attached() {
    // 获取当前页面路径
    const pages = getCurrentPages();
    const currentPage = pages[pages.length - 1];
    const route = currentPage.route;
    
    // 找到当前页面对应的tabBar项的索引
    const index = this.data.list.findIndex(item => item.pagePath === `/${route}`);
    if (index !== -1) {
      this.setData({
        selected: index
      });
    }
  },
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset;
      const index = data.index;
      const url = this.data.list[index].pagePath;
      
      // 切换到对应页面
      wx.switchTab({
        url
      });
      
      // 更新选中状态
      this.setData({
        selected: index
      });
    }
  }
}) 